﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.DA;
using Com.BU;

namespace ThermalEquipmentDesign.Model.Condenser.VerticalPipeR717
{
    public class VerticalPipeR717 : ObservableObject
    {
        // Declare fields for inputting
        #region Feild Input
        private double dbcoldProductivity;
        private double dbcondensationTemperature;
        private double dbwaterTemperature;
        private double dbdegreeIncreaseTemp;
        private double dbpipeLenght;
        private double dbinterDiameter = 0.051;
        private double dbexterDiameter = 0.057;
        private double dbwaterThermalCapacity;
        private double dbkinematicViscosity;
        private double dbdynamicViscosity;
        private double dbheatConductivityCoefficient;
        private double dbprandtlCoefficient;
        private double dbthermalResistance = 0.6 * Math.Pow(10, -3);
        private double dbdiffTemp;
        #endregion

        // Create properties for fields
        #region Properties Input
        public double dbColdProductivity
        {
            get { return dbcoldProductivity; }
            set
            {
                if (value != dbcoldProductivity)
                {
                    dbcoldProductivity = value;
                    OnPropertyChanged("dbColdProductivity");
                }
            }
        }

        public double dbCondensationTemperature
        {
            get { return dbcondensationTemperature; }
            set { dbcondensationTemperature = value; }
        }

        public double dbWaterTemperature
        {
            get { return dbwaterTemperature; }
            set {
                if (value != dbwaterTemperature)
                {
                    dbwaterTemperature = value;
                    SetAverageTemp();
                    OnPropertyChanged("dbWaterTemperature");
                }                
            }
        }

        public double dbDegreeIncreaseTemp
        {
            get { return dbdegreeIncreaseTemp; }
            set {
                if (value != dbdegreeIncreaseTemp)
                {
                    dbdegreeIncreaseTemp = value;
                    SetAverageTemp();
                    OnPropertyChanged("dbDegreeIncreaseTemp");
                }                    
            }
        }

        public double dbPipeLenght
        {
            get { return dbpipeLenght; }
            set { dbpipeLenght = value; }
        }

        public double dbInterDiameter
        {
            get { return dbinterDiameter; }
            set { dbinterDiameter = value; }
        }

        public double dbExterDiameter
        {
            get { return dbexterDiameter; }
            set { dbexterDiameter = value; }
        }

        public double dbWaterThermalCapacity
        {
            get { return dbwaterThermalCapacity; }
            set { dbwaterThermalCapacity = value; }
        }

        public double dbKinematicViscosity
        {
            get { return dbkinematicViscosity; }
            set { dbkinematicViscosity = value; }
        }

        public double dbDynamicViscosity
        {
            get { return dbdynamicViscosity; }
            set { dbdynamicViscosity = value; }
        }

        public double dbHeatConductivityCoefficient
        {
            get { return dbheatConductivityCoefficient; }
            set { dbheatConductivityCoefficient = value; }
        }

        public double dbPrandtlCoefficient
        {
            get { return dbprandtlCoefficient; }
            set { dbprandtlCoefficient = value; }
        }

        public double dbThermalResistance
        {
            get { return dbthermalResistance; }
            set { dbthermalResistance = value; }
        }

        public double dbDiffTemp
        {
            get { return dbdiffTemp; }
            set { dbdiffTemp = value; }
        }
        #endregion

        /// <summary>
        /// Change value foe properties that realted with average temperature
        /// </summary>
        private void SetAverageTemp()
        {
            double dbaverageTemp = (2 * dbwaterTemperature + dbdegreeIncreaseTemp) * 0.5;
            tb_water_coefficients watercoefficients = LibraryManagerInCom.WaterCoefficientsList.SingleOrDefault(w => w.Temperature == dbaverageTemp);

            if (watercoefficients != null)
            {
                dbwaterThermalCapacity = (double)watercoefficients.HeatSpecific;
                dbkinematicViscosity = (double)watercoefficients.KinematicViscosity;
                dbdynamicViscosity = (double)watercoefficients.DynamicViscosity;
                dbheatConductivityCoefficient = (double)watercoefficients.HeatConductivity;
                dbprandtlCoefficient = (double)watercoefficients.Prandtl_Coefficient;
                OnPropertyChanged("dbWaterThermalCapacity");
                OnPropertyChanged("dbKinematicViscosity");
                OnPropertyChanged("dbDynamicViscosity");
                OnPropertyChanged("dbHeatConductivityCoefficient");
                OnPropertyChanged("dbPrandtlCoefficient");
            }
        }
    }
}
